package com.example.xm.adapter.HomeAdapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.xm.R;
import com.example.xm.base.BaseAdapter;
import com.example.xm.bean.HomeBean.HomePhotoBean;

import java.util.List;

public class HomePhotoAdapter extends BaseAdapter {

    public HomePhotoAdapter(Context context, List data) {
        super(context, data);
    }

    @Override
    protected int getLayout() {
        return R.layout.home_photo_item;
    }

    @Override
    protected void bindData(BaseViewHolder viewHolder, Object o) {
        ImageView img = (ImageView) viewHolder.getViewById(R.id.iv_img);
        TextView title = (TextView) viewHolder.getViewById(R.id.tv_title_photo);
        ImageView head = (ImageView) viewHolder.getViewById(R.id.iv_head_photo);
        TextView name = (TextView) viewHolder.getViewById(R.id.tv_name_photo);
        ImageView zan = (ImageView) viewHolder.getViewById(R.id.iv_zan);
        TextView zannum = (TextView) viewHolder.getViewById(R.id.tv_zan_num_photo);

        HomePhotoBean.DataBean.DynamicsBean bean = (HomePhotoBean.DataBean.DynamicsBean) o;
        List<HomePhotoBean.DataBean.DynamicsBean.ImagesBean> images = bean.getImages();
        ViewGroup.LayoutParams layoutParams = img.getLayoutParams();
        int imageWidth = images.get(0).getImageWidth();
        int imageHeight = images.get(0).getImageHeight();
        layoutParams.width = imageWidth/2;
        layoutParams.height = imageHeight/2;
        Glide.with(context).load(images.get(0).getFilePath()).into(img);
        title.setText(bean.getContent());

        RequestOptions requestOptions = new RequestOptions().circleCrop();
        Glide.with(context).load(bean.getHeadUrl()).apply(requestOptions).into(head);

        name.setText(bean.getNickName());
        zannum.setText(bean.getLikeNumber() + "");
    }
}
